
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

void sigint_handler(int sig) {
    int cnt = 20;
    while(cnt--){
        printf("Received SIGINT\n");
        sleep(1);
    }
}

void sigterm_handler(int sig) {
    int cnt = 20;
    while(cnt--){
        printf("Received SIGTERM\n");
        sleep(1);
    }
}

int main() {
    struct sigaction act;
    act.sa_handler = sigint_handler;  // 设置SIGINT的处理函数
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    sigaction(SIGINT, &act, NULL);

    act.sa_handler = sigterm_handler; // 设置SIGTERM的处理函数
    sigaction(SIGTERM, &act, NULL);

    while (1) {
        printf("Waiting for signals...\n");
        sleep(1);
    }
    return 0;
}
//A process receives two different signals, the first signal code will be blocked,
// execute the second signal, wait for the second signal to complete execution, 
// and then execute the remaining code of the first signal.